<!--
 * @Author: 冯尚新 fengshangxin@yunjinhz.com
 * @Date: 2023-05-23 10:51:57
 * @LastEditors: 冯尚新 fengshangxin@yunjinhz.com
 * @LastEditTime: 2023-12-26 21:09:34
 * @FilePath: \zmglpt-ui-mobile-v1.1\dev\pages\dashboard\dashboard.vue
 * @Description: 行业标准版-首页
-->

<template>
	<view class="page">
		<view class="custom-lay">
			<!-- #ifdef H5-ONLY -->
			<theme-navbar :is-white="true" :borderBottom="false" :is-back="false" :title="navTitle"></theme-navbar>
			<!-- #endif -->
			<view class="custom-head-img">
				<u-image mode="widthFix" width="100%" src="/static/banner_bg.png"></u-image>
			</view>
		</view>
		<view class="user-img">
			<text style="margin: 6rpx 0rpx 2rpx 20rpx;" @click="showSwitchDept()">
				欢迎您、{{ user.user.personName }} &nbsp;&nbsp; {{ user.deptName }}
			</text>
			<u-icon name="arrow-right" style="margin: 6rpx 0rpx 2rpx 0rpx;" v-if="hasExDepart" size="30"
				@click="showSwitchDept()"></u-icon>
		</view>
		<view class="content content-bg">
			<template v-for="(itm, index) in configs">
				<view :key="itm.menuid">
					<u-gap v-if="index != 0" :height="$theme.cm_section_top_gap_height" :bg-color="$theme.cm_gap_color"></u-gap>
					<view class="tt">{{ itm.menuname }}</view>
					<u-grid :col="4" :border="false">
						<u-grid-item v-for="(item, index) in itm.children" :key="item.menuid" :index="index"
							@click="gridClick(item)">
							<u-badge type="primary" count="测" v-if="item.isFinish"></u-badge>
							<u-image width="40px" mode="widthFix" :src="WORKBENCH_ICON[item.menucode]"></u-image>
							<view class="grid-text">{{ item.menuname }}</view>
						</u-grid-item>
					</u-grid>
					<u-gap v-if="index == configs.length - 1" :height="$theme.cm_section_top_gap_height"
						:bg-color="$theme.cm_gap_color"></u-gap>
				</view>
			</template>
		</view>
	</view>
</template>

<script>
	import caseService from '@/service/case/case.service';
	import commonService from '@/service/common/common.service.js';
	import {
		WORKBENCH_ICON,
	} from "@/service/common/mapping/enum.js";

	export default {
		data() {
			return {
				user: this.$store.state.userInfo,
				// configKeys: [{title: '工作待办',ext: 'gzdb',},{title: '专卖查询',ext: 'zmcx',},{title: '专卖作业',ext: 'zmzy',},{title: '内管作业',ext: 'ngzy',}],
				configs: [],
				WORKBENCH_ICON: WORKBENCH_ICON,
				deptChoiceShow: false,
				deptList: [],
				exdepts: [],
			};
		},
		computed: {
			hasExDepart() {
				if (this.user.user.exDeparts && this.user.user.exDeparts.length > 0) return true;
				return false;
			},
		},

		onLoad(data) {
			console.log(WORKBENCH_ICON)
			this.initIntent();
			if (data.id == 'qb') {
				this.$u.route({
					url: '/pages/case/index',
				});
			}

		},
		mounted() {
			this.updateMixinTitle('移动专卖');
			this.exdepts = [this.user.user.depart, ...this.user.user.exDeparts, ];
			this.exdepts.forEach(ixx => {
				if (this.user.deptCode == ixx.orgCode) {
					this.deptList.push({
						text: `${this.user.user.org.orgShortName}-${ixx.orgShortName}`,
						color: this.$theme.u_type_primary,
					});
				} else {
					this.deptList.push({
						text: `${ixx.townOrgName}-${ixx.orgShortName}`,
					});
				}
			});

		},
		methods: {
			showSwitchDept() {
				if (!this.hasExDepart) return;
				this.deptChoiceShow = true;
			},
			initIntent() {
				this.$modal.showLoading('请求资源中...');
				commonService.getListMenus().then(res => {
					this.$modal.hideLoading();
					if (res.code == 200 && res.success) {
						if ( !!res.bean ) {
							this.configs = JSON.parse(res.bean);
						} else {
							this.$modal.alert("菜单未分配，请联系管理员进行分配。");
						}
					} else {
						this.$modal.alert(res.msg);
					}

				}).catch(err => {
					this.$modal.hideLoading();
					this.$modal.alert(err.msg);
				});

				// this.configs = [
				// {
				// id: 'ZMYWSP',
				// image: '../../static/dashboard/gzdb.png',
				// url: '/pages/todo/dashboard',
				// title: '统一待办',
				// isFinish: false,
				// isShow: false,
				// ext: 'gzdb',
				// },
				// {
				// id: 'JYXXCX',
				// image: '../../static/dashboard/jyxx.png',
				// url: '/pages/query/cigaretteLogoQuery/cigaretteLogoQuery',
				// title: '卷烟信息',
				// isFinish: false,
				// isShow: false,
				// ext: 'zmcx',
				// },
				// {
				// id: 'JGDXCX',
				// image: '../../static/dashboard/jgdx.png',
				// url: '/pages/query/regulationQuery',
				// title: '监管对象',
				// isFinish: false,
				// isShow: false,
				// ext: 'zmcx',
				// },
				// {
				// id: 'MDCX',
				// image: '../../static/dashboard/mdcx.png',
				// url: '/pages/query/barCode/queryBarCode',
				// title: '码段查询',
				// isFinish: false,
				// isShow: false,
				// ext: 'zmcx',
				// },
				// {
				// id: 'YJSS',
				// image: '../../static/dashboard/yjss.png',
				// url: '/pages/keySearch/dashboard',
				// title: '一键搜索',
				// isFinish: false,
				// isShow: false,
				// ext: 'zmcx',
				// },
				// {
				// id: 'XKTJ',
				// image: '../../static/dashboard/xktj.png',
				// url: '/pages/query/stats/statsCom',
				// title: '许可统计',
				// isFinish: false,
				// isShow: false,
				// ext: 'zmcx',
				// },
				// {
				// id: 'AJTJ',
				// image: '../../static/dashboard/ajtj.png',
				// url: '/pages/query/stats/caseStats',
				// title: '案件统计',
				// isFinish: false,
				// isShow: false,
				// children: [],
				// ext: 'zmcx',
				// },
				// {
				// id: 'YJTX',
				// image: '../../static/dashboard/yjtx.png',
				// url: '/pages/query/earlyWarning/earlywarnList',
				// title: '预警提醒',
				// isFinish: false,
				// isShow: false,
				// ext: 'zmcx',
				// },
				// {
				// id: 'TZGG',
				// image: '../../static/dashboard/tzgg.png',
				// url: '/pages/notice/noticeList',
				// title: '通知公告',
				// isFinish: false,
				// isShow: false,
				// ext: 'zmcx',
				// },
				// {
				// id: 'YWSP',
				// image: '../../static/dashboard/zmywsp.png',
				// url: '/pages/todo/dashboard?just=zm',
				// title: '专卖审批',
				// isFinish: false,
				// isShow: false,
				// ext: 'zmzy',
				// },
				// {
				// id: 'DAKB',
				// image: '../../static/dashboard/dakb.png',
				// url: '/pages/majorCaseReport/majorCaseReportList',
				// title: '大案快报',
				// isFinish: false,
				// isShow: false,
				// ext: 'zmzy',
				// },
				// {
				// id: 'SCJC',
				// image: '../../static/dashboard/scjc.png',
				// url: '/pages/check/dashboard',
				// title: '市场检查',
				// isFinish: false,
				// isShow: false,
				// ext: 'zmzy',
				// },
				// {
				// id: 'AJCB',
				// image: '../../static/dashboard/ajcb.png',
				// url: '/pages/case/index',
				// title: '案件查办',
				// isFinish: false,
				// isShow: false,
				// ext: 'zmzy',
				// },
				// {
				// id: 'XKHC',
				// image: '../../static/dashboard/xkhc.png',
				// url: '/pages/certificate/fieldAuditList/fieldAuditList',
				// title: '许可核查',
				// isFinish: false,
				// isShow: false,
				// ext: 'zmzy',
				// },
				// {
				// id: 'QBGL',
				// image: '../../static/dashboard/qbgl.png',
				// url: '/pages/intelligence/dashboard',
				// title: '情报管理',
				// isFinish: false,
				// isShow: false,
				// ext: 'zmzy',
				// },
				// {
				// id: 'SCJHLKH',
				// image: '../../static/dashboard/scjhl.png',
				// url: '/pages/mprEvaluation/mprEvaluationPlanList',
				// title: '市场净化率',
				// isFinish: false,
				// isShow: false,
				// ext: 'zmzy',
				// },
				// {
				// id: 'NGYWSP',
				// image: '../../static/dashboard/ngywsp.png',
				// url: '/pages/todo/dashboard?just=ng',
				// title: '内管审批',
				// isFinish: false,
				// isShow: false,
				// ext: 'ngzy',
				// },
				// {
				// id: 'NGSDHC',
				// image: '../../static/dashboard/sdhc.png',
				// url: '/pages/internal/fieldAudit/index',
				// title: '实地核查',
				// isFinish: false,
				// isShow: false,
				// ext: 'ngzy',
				// },
				// {
				// id: 'GYXT',
				// image: '../../static/dashboard/gwxt.png',
				// url: '/pages/internal/docFrame/components/coordinationStart',
				// title: '岗员协同',
				// isFinish: false,
				// isShow: false,
				// ext: 'ngzy',
				// },
				// {
				// id: 'SAWZ',
				// image: '../../static/dashboard/icon_sawzcx.png',
				// url: '/pages/store/storeEntry',
				// title: '涉案物资',
				// isFinish: false,
				// isShow: false,
				// ext: 'zmcx',
				// },
				// ];

				// this.configs.push(
				// {
				// id: 'DEMO',
				// image: '../../static/common/icon_ydba.png',
				// url: '/pages/demo/index',
				// title: 'Demo示例',
				// isFinish: false,
				// isShow: false,
				// ext: 'gzdb',
				// },	
				// );																	
			},
			getUseConfigs(ext) {
				return this.configs.filter((itm) => {
					return itm.ext == ext;
				});
			},
			gridClick: function(item) {
				if (!this.$u.test.isEmpty(item.url)) {
					this.$u.route(item.url);
				} else {
					this.$modal.alert('功能未实现');
				}
			},
			updateBackState(par) {},
			switchDept(index) {
				let depart = this.exdepts[index];
				if (this.user.deptCode == depart.orgCode) return;
				this.$modal.showLoading('正在切换部门');
				commonService.switchDept({
					deptUuid: depart.orgUuid,
				}).then(dr => {
					this.$modal.hideLoading();
					if (dr.success) {
						uni.setStorageSync("tk", dr.bean.tk);
						sessionStorage.setItem("tk", dr.bean.tk);
						this.$store.state.userInfo = dr.bean;
						uni.setStorageSync("user", JSON.stringify(dr.bean));
						this.$u.route({
							type: "redirect",
							url: "/pages/dashboard/dashboard",
						});
					} else {
						console.log(dr.msg);
						this.$u.toast('切换部门失败,请联系管理员!');
					}
				}).catch(eop => {
					console.log(eop);
					this.$modal.hideLoading();
					this.$u.toast('切换部门失败,请联系管理员!');
				});
			},

		},
	};
</script>

<style lang="scss" scoped>
	uni-page-body {
		height: 100%;
	}

	.page {
		padding: 0;
	}

	.tt {
		font-size: 34rpx;
		font-weight: 600;
		line-height: 40px;
		color: #121c33;
		margin-top: 20rpx;
		padding-left: $cm-content-paddng-row;
		padding-right: $cm-content-paddng-row;
	}

	.custom-lay {
		position: relative;

		.custom-head-img {
			display: flex;
			justify-content: center;
		}
	}

	.grid-text {
		font-weight: 400;
		color: #121c33;
		font-size: 28rpx;
	}

	.page {
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;

		.nav-right-icon {
			margin-right: 30rpx;
			font-size: 0.8rem;
		}

		.user-img {
			display: flex;
			background-image: linear-gradient(to right, #edf3fd 50%, #ffffff00);
			width: 100%;
			padding: 12rpx 10rpx;
			font-size: 28rpx;
			color: #53a4fe;
		}

		.content {}

		.content-bg {
			background-color: #fff;
		}

		.slot-wrap {
			display: flex;
			align-items: center;
		}

		.navbar-right {
			margin-right: 24rpx;
			display: flex;
		}

		.right-item {
			margin: 0 12rpx;
			position: relative;
			color: $u-main-color;
			display: flex;
		}
	}

	.pre-lay {
		display: inline-flex;
		flex-direction: row;
		justify-content: flex-start;
		align-content: center;
		align-items: center;

		uni-text {
			font-size: 32rpx;
			color: $u-type-primary;
			margin-left: 20rpx;
		}
	}
</style>